package com.swak.utils;

/**
 * Functions
 *
 * @author: lifeng
 * @date: 2020/3/29 14:07
 */
public final class Functions {
	private Functions() {
	}

	@FunctionalInterface
	public interface ThrowableFunction {

		/**
		 * Executes the action
		 *
		 * @throws Throwable if met with error
		 */
		void execute() throws Throwable;

		/**
		 * Executes {@link ThrowableFunction}
		 *
		 * @param action {@link ThrowableFunction}
		 * @throws RuntimeException wrap {@link Exception} to {@link RuntimeException}
		 */
		static void execute(ThrowableFunction action) throws RuntimeException {
			try {
				action.execute();
			} catch (Throwable e) {
				throw new RuntimeException(e);
			}
		}
	}
}
